<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <!--  卡片视图 -->
    <el-card>
      <!-- 2.0 准备相关的数据展示盒子，设置宽高 -->
      <div
        ref="boxRef"
        style="width: 800px; height: 500px;"
      ></div>
    </el-card>
  </div>
</template>

<script>
// 1.0 导入 echarts 数据展示的包
import echarts from 'echarts'
import _ from 'lodash'

export default {
  data() {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  // 3.0 在页面渲染完毕之后调用相关方法
  async mounted() {
    // 3.1 获取页面元素
    let myChart = echarts.init(this.$refs.boxRef)
    let { data: res } = await this.$http.get('reports/type/1')
    if (res.meta.status !== 200) return this.$message.error('数据请求失败')

    // 4.0 准备相关的配置参数
    let data = _.merge(res.data, this.options)

    // 5.0 展示图表
    myChart.setOption(data)
  }
}
</script>

<style lang="less" scoped>
</style>